﻿using B.S.Shop.Infartructrue.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.Shop.Infartructrue.Implment
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        public BaseRepository(MyDbContext myDb)
        {
            MyDb = myDb;
        }

        public MyDbContext MyDb { get; }


        public IQueryable<T> GetAll()
        {
            return MyDb.Set<T>();
        }

        public async Task<int> AddAsync(T entity)
        {
            await MyDb.Set<T>().AddAsync(entity);
            return  await MyDb.SaveChangesAsync();
        }


        public async Task<int> UpdateAsync(T entity)
        {
             MyDb.Set<T>().Update(entity);
            return await MyDb.SaveChangesAsync();
        }

        public async Task<int> UpdateRange(List<T> entities)
        {
             MyDb.Set<T>().UpdateRange(entities);
            return await MyDb.SaveChangesAsync();
        }
    }
}
